package com.Monica;

import com.Person;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class AjaxServlet extends BaseServlet{

    protected void javaScriptAjax(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("AJAX请求过来了");
        Person person = new Person(1,"国哥");
        Gson gson = new Gson();
        String personjsonString = gson.toJson(person);
        System.out.println(personjsonString);
        response.getWriter().write(personjsonString);
    }

    protected void jQueryAjax(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("jQueryAjax请求过来了");
        Person person = new Person(1,"国哥");
        Gson gson = new Gson();
        String personjsonString = gson.toJson(person);
        System.out.println(personjsonString);
        response.getWriter().write(personjsonString);
    }

    protected void jQueryPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("Post请求被调用");
        Person person = new Person(1,"国哥");
        Gson gson = new Gson();
        String personjsonString = gson.toJson(person);
        System.out.println(personjsonString);
        response.getWriter().write(personjsonString);
    }

    protected void jQueryGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("Get请求被调用");
        Person person = new Person(1,"国哥");
        Gson gson = new Gson();
        String personjsonString = gson.toJson(person);
        System.out.println(personjsonString);
        response.getWriter().write(personjsonString);
    }

    protected void jQueryGetJSON(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("GetJson请求被调用");
        Person person = new Person(1,"国哥");
        Gson gson = new Gson();
        String personjsonString = gson.toJson(person);
        System.out.println(personjsonString);
        response.getWriter().write(personjsonString);
    }

    protected void jQuerySerialize(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("jQuerySerialize请求被调用");
        System.out.println("账号:" + request.getParameter("username"));
        System.out.println("密码:" + request.getParameter("password"));
        Person person = new Person(1,"国哥");
        Gson gson = new Gson();
        String personjsonString = gson.toJson(person);
        System.out.println(personjsonString);
        response.getWriter().write(personjsonString);
    }
}
